home *** CD-ROM | disk | FTP | other *** search
- /* feof.c */
- #include <stdio.h>
- main()
- {
- FILE *infile;
- unsigned char buffer[81];
- /* Open the file "c:\autoexec.bat". We need two '\' */
- if ((infile = fopen("c:\\autoexec.bat", "r")) == NULL)
- {
- perror ("fopen failed.\n");
- exit(0);
- }
- printf("Contents of c:\autoexec.bat:\n");
- while (fgets(buffer, 80, infile) != NULL)
- {
- printf(buffer);
- }
- if (feof(infile) != 0) /* Check end-of-file */
- {
- printf("*** End-of-file reached ***");
- }
- else
- {
- printf("ERROR: reading from file!\n");
- }
- }